package cz.muni.fi.pa165.library.web_layer;

import cz.muni.fi.pa165.library.web_layer.adminPages.MenuAdminPanel;
import cz.muni.fi.pa165.library.web_layer.readerPages.MenuReaderPanel;
import java.util.Locale;
import org.apache.wicket.Session;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.model.Model;
import org.apache.wicket.request.mapper.parameter.PageParameters;
/**
 *
 * @author dulinka
 */
public class Template extends WebPage {
    
	private static final long serialVersionUID = 1L;

        public Template(final PageParameters parameters) {
        super(parameters);       
        
        AuthenticatedSession session = ((AuthenticatedSession)Session.get());
       
        if (session.getUser()!=null){
            add(new Label("user",session.getUser()));
            add(new Label("login",new Model("")));
           add(new BookmarkablePageLink<>("logout", Logout.class));
           if (session.getCheckAdmin()){
                add(new MenuAdminPanel("menuPanel"));
            }else {
                add(new MenuReaderPanel("menuPanel"));
            }
        }else {
            add(new Label("user",""));
            add(new BookmarkablePageLink<>("login", Login.class));
            add(new Label("logout",new Model("")));
            add(new MenuPanel("menuPanel"));
        }


        Link enLocalisation = (new Link("en") {
            @Override
            public void onClick()
            {
                getSession().setLocale(new Locale("en"));
            }
        });
        add(enLocalisation);
        
        Link skLocalisation = (new Link("sk") {
            @Override
            public void onClick()
            {
                getSession().setLocale(new Locale("sk"));
            }
        });
        add(skLocalisation);
             
        
        }
}
